﻿@using Models
@model Users

@{
    
    ViewBag.Title = "Update user";
}
<div style="float: left; height: 70px"><a href="/admin/index" ><img src="/Content/images/back.png" /></a></div>
<div style="margin-left: 80px;"><a href="/admin/AllUsers" ><img src="/content/images/Users_group.png" alt="All users" /><br />All users</a></div>
<h2>Update user</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@if (ViewBag.Message != null)
{
    @ViewBag.Message
}
else
{
    using (Html.BeginForm("UpdateUser", "Admin", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
        @Html.ValidationSummary()
        <table id="table_admin">
            <tr>
                <td>
                    Password
                </td>
                <td>
                    @Html.PasswordFor(x => x.Pwd)
                </td>
            </tr>
            <tr>
            <td>
                @Html.LabelFor(x => x.ConfirmPwd)
            </td>
            <td>
                @Html.PasswordFor(x => x.ConfirmPwd)
            </td>
        </tr>
            <tr>
                <td>
                    Email
                </td>
                <td>
                    @Html.TextBoxFor(x => x.Email)
                </td>
            </tr>
            <tr>
                <td>
                    Role
                </td>
                <td>
                    @{
                        var roles = new List<Role>
                                    {
                                        new Role{Id = 1, Name = "Administrator"},
                                        new Role{Id = 2, Name = "Editor"},
                                        new Role{Id = 3, Name = "User"}
                                    };
                        @Html.DropDownListFor(x => x.Role, new SelectList(roles,"Id","Name",1))
                }
                
                </td>
            </tr>
            <tr>
                <td>
                    Name
                </td>
                <td>
                    @Html.TextBoxFor(x => x.Name)
                </td>
            </tr>
            <tr>
                <td>
                    Last
                </td>
                <td>
                    @Html.TextBoxFor(x => x.FName)
                </td>
            </tr>
            <tr>
                <td>
                    Middle
                </td>
                <td>
                    @Html.TextBoxFor(x => x.MName)
                </td>
            </tr>
            <tr>
                <td>
                    @if(Model.Image != null)
                    {
                        <img id="image_in_news" src="@Model.Image" alt="@Model.Name avatar"/>
                    }
                    else
                    {
                        <span>No image uploaded</span>
                    }
                </td>
                <td>
                    <input type="file" name="uploadfile"/>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    @Html.HiddenFor(x=>x.Login)
                    @Html.HiddenFor(x=>x.Image)
                    @Html.HiddenFor(x=>x.Id)
                    <input type="submit" name="subUpdateUser" value="Edit"/>
                </td>
            </tr>
        </table>
    }
}